const query = require('../../db/db')
//token 包
const jwt = require('jsonwebtoken')
//导入密钥全局配置文件
const config = require('../../config')
//获取用户基本信息
exports.getUserInfo = async (req, res) => {
    try {
        const email = req.auth.email
        let sql = 'select * from ev_users_email where email = ?'
        console.log("asd", email);
        const result = await query(sql, email)
        console.log(result);
        if (result.length !== 1) return res.cc('获取用户信息失败')
        //在服务器端生成token
        const user = { ...result[0], password: '', }
        const tokenStr = jwt.sign(user, config.jwtSecretKey, { expiresIn: config.expiresIn })
        //获取成功
        res.send({
            status: 0,
            data: { ...result[0], password: '************' },
            token: 'Bearer ' + tokenStr
        })
    } catch (error) {
        console.log(error);
        res.send('服务器异常')
    }
}

